#import "UIImageView+WebCache.h"
#import <MediaPlayer/MediaPlayer.h>
#import "ZQBaseCell.h"
@interface ZQBaseCell()
@property (weak, nonatomic) IBOutlet UIImageView *videoImg;
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UILabel *videoTime;
@end
@implementation ZQBaseCell
- (void)awakeFromNib {
    [super awakeFromNib];
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
}
- (void)setZqBaseModel:(ZQBaseModel *)zqBaseModel
{
    _zqBaseModel = zqBaseModel;
    [self.videoImg sd_setImageWithURL:[NSURL URLWithString:zqBaseModel.cover]];
    [self.titleLabel setText:zqBaseModel.title];
    self.videoTime.text = [NSString stringWithFormat:@"%02zd:%02zd",zqBaseModel.duration / 60 ,zqBaseModel.duration % 60];
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(doTap)];
    self.videoImg.userInteractionEnabled = YES;
    [self.videoImg addGestureRecognizer:tap];
}
- (UIViewController *)topViewController {
    UIViewController *resultVC;
    resultVC = [self _topViewController:[[UIApplication sharedApplication].keyWindow rootViewController]];
    while (resultVC.presentedViewController) {
        resultVC = [self _topViewController:resultVC.presentedViewController];
    }
    return resultVC;
}
- (UIViewController *)_topViewController:(UIViewController *)vc {
    if ([vc isKindOfClass:[UINavigationController class]]) {
        return [self _topViewController:[(UINavigationController *)vc topViewController]];
    } else if ([vc isKindOfClass:[UITabBarController class]]) {
        return [self _topViewController:[(UITabBarController *)vc selectedViewController]];
    } else {
        return vc;
    }
    return nil;
}
#pragma mark - === doTap ===
- (void)doTap
{
    NSURL *url = [NSURL URLWithString:_zqBaseModel.url];
    MPMoviePlayerViewController * moview = [[MPMoviePlayerViewController alloc]initWithContentURL:url];
    [[self topViewController].navigationController pushViewController:moview animated:YES];
}
@end
